I'm gonna overwrite a lot of this notebook's old content. I changed the way I'm calculating wt, and wanna test that my training worked.


In [1]:
from pearce.emulator import OriginalRecipe, ExtraCrispy
from pearce.mocks import cat_dict
import numpy as np
from os import path

In [2]:
import matplotlib
#matplotlib.use('Agg')
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()

In [3]:
training_dir = '/u/ki/swmclau2/des/PearceLHC_ds_z/'

em_method = 'gp'
split_method = 'random'

In [4]:
%%bash
ls -d ~/des/PearceLHC_wt_z/*


/u/ki/swmclau2/des/PearceLHC_wt_z/a_0.81120

In [5]:
a = 0.81120
z = 1.0/a - 1.0

In [6]:
fixed_params = {'z':z}#, 'r':0.18477483}
n_leaves, n_overlap = 10, 2 emu = ExtraCrispy(training_dir, n_leaves, n_overlap, split_method, method = em_method, fixed_params=fixed_params)

In [7]:
emu = OriginalRecipe(training_dir, method = em_method, fixed_params=fixed_params, independent_variable=None)

In [8]:
emu._ordered_params


Out[8]:
OrderedDict([('logMmin', (11.5, 13.0)),
             ('sigma_logM', (0.05, 1.0)),
             ('logM0', (10, 13)),
             ('logM1', (12.0, 15.0)),
             ('alpha', (0.8, 1.5)),
             ('f_c', (0.05, 0.5)),
             ('mean_occupation_satellites_assembias_param1', (-1.0, 1.0)),
             ('mean_occupation_centrals_assembias_param1', (-1.0, 1.0)),
             ('r', (0.095817335000000003, 33.997273184999997))])

In [9]:
print emu.y


[ 0.78066169  0.81532135  0.83564333 ..., -0.87369104 -0.95706053
 -1.03126027]
params = {} params['logMmin'] = 13.4 params['sigma_logM'] = 0.1 params['f_c'] = 0.19 params['alpha'] = 1.0 params['logM1'] = 14.0 params['logM0'] = 12.0 params['mean_occupation_centrals_assembias_param1'] = 0.0 params['mean_occupation_satellites_assembias_param1'] = 0.0

In [10]:
emu.x[0,:-1]


Out[10]:
array([ 11.774,   0.246,  10.018,  12.397,   1.228,   0.156,   0.86 ,
         0.984])

In [11]:
emu._ordered_params.items()


Out[11]:
[('logMmin', (11.5, 13.0)),
 ('sigma_logM', (0.05, 1.0)),
 ('logM0', (10, 13)),
 ('logM1', (12.0, 15.0)),
 ('alpha', (0.8, 1.5)),
 ('f_c', (0.05, 0.5)),
 ('mean_occupation_satellites_assembias_param1', (-1.0, 1.0)),
 ('mean_occupation_centrals_assembias_param1', (-1.0, 1.0)),
 ('r', (0.095817335000000003, 33.997273184999997))]

In [13]:
l = len(emu.scale_bin_centers)
idx = 0
params = {pname:pval for pname, pval in zip(emu._ordered_params.iterkeys(), emu.x[idx*l,:-1])}

In [14]:
params['logMmin'] = 12.1
params['sigma_logM'] = 0.3
params['logM0'] = 12
params['logM1'] = 13.2
params['f_c'] = 0.2
params['alpha'] = 1.0
params['mean_occupation_centrals_assembias_param1'] = 0.0
params['mean_occupation_satellites_assembias_param1'] = 0.0

In [15]:
for k,v in params.iteritems():
    print k,'\t'*5,v


logMmin 					12.1
mean_occupation_centrals_assembias_param1 					0.0
f_c 					0.2
logM0 					12
sigma_logM 					0.3
mean_occupation_satellites_assembias_param1 					0.0
logM1 					13.2
alpha 					1.0

In [16]:
ds = emu.emulate_wrt_r(params, emu.scale_bin_centers)[0]
plt.plot(emu.scale_bin_centers, ds, label = 'Emu')
l = len(emu.scale_bin_centers)
plt.plot(emu.scale_bin_centers, emu.y[(idx)*l:(idx+1)*l]+emu.y_hat, label = 'Training')
plt.ylabel(r'$\Delta \Sigma(r)$')
plt.xlabel(r'$r \; \mathrm{[Mpc]}$')
#plt.loglog();
plt.xscale('log')
plt.legend(loc='best')


/u/ki/swmclau2/.conda/envs/hodemulator/lib/python2.7/site-packages/pearce/emulator/emu.py:444: UserWarning: One value for r is outside the bounds (0.096, 33.997) of the emulator.
  pname, plow, phigh))
Out[16]:
<matplotlib.legend.Legend at 0x7fe64daa6210>

In [ ]:
cosmo_params = {'simname':'chinchilla', 'Lbox':400.0, 'scale_factors':[a]}
cat = cat_dict[cosmo_params['simname']](**cosmo_params)#construct the specified catalog!

cat.load_catalog(a, particles = True)
cat.load_model(a, 'hsabRedMagic')
#halo_masses = cat.halocat.halo_table['halo_mvir']

In [ ]:
emu.scale_bin_centers

In [ ]:
scale_bins = np.logspace(-1.1, 1.6, 19)
param_name = 'alpha' bounds = emu.get_param_bounds(param_name) param_vals = np.linspace(bounds[0]+0.1, bounds[1]-0.1, 6) dss = [] for pv in param_vals: params[param_name] = pv cat.populate(params) ds = cat.calc_ds(scale_bins) dss.append(ds)
for ds, pv in zip(dss, param_vals): plt.plot(emu.scale_bin_centers, ds, label = '%.1f'%pv) plt.title("Mock w.r.t. %s"%param_name) plt.ylabel(r'$\Delta \Sigma(r) \mathrm{[h\; M_{\odot}/pc^2]}$') plt.xlabel(r'$r \; \mathrm{[Mpc]}$') plt.loglog(); plt.xlim([8e-2, 2e1]) plt.ylim([1e-2, 5]) plt.legend(loc='best')

In [20]:
param_name = 'logMmin'
bounds = emu.get_param_bounds(param_name)
param_vals = np.linspace(bounds[0]+0.1, bounds[1]-0.1, 6)

for pv in param_vals:
    params[param_name] = pv
    ds = emu.emulate_wrt_r(params, emu.scale_bin_centers)[0]
    plt.plot(emu.scale_bin_centers, ds, label = '%.1f'%pv)
    
plt.title("Emulator w.r.t. %s"%param_name)
plt.ylabel(r'$ \log \Delta \Sigma(r) \mathrm{[h\; M_{\odot}/pc^2]}$')
plt.xlabel(r'$r \; \mathrm{[Mpc]}$')
plt.xscale('log');
#plt.xlim([8e-2, 2e1])
#plt.ylim([1e-2, 5])
plt.legend(loc='best')


Out[20]:
<matplotlib.legend.Legend at 0x7fe64d744f50>

In [ ]:
print wt
binlen = 19 for b in xrange(5): plt.plot(emu.scale_bin_centers, emu.y[b*binlen:(b+1)*binlen]+1) params = dict(zip(emu._ordered_params.keys(), emu.x[b*binlen+1,:-1])) pred = emu.emulate_wrt_r(params, emu.scale_bin_centers)[0] plt.plot(emu.scale_bin_centers, 1+pred, ls = '--') #plt.ylim([0.9, 1.5]) plt.xscale('log') plt.legend(loc='best') plt.xlim([0.1, 4]) plt.title(r'$w(\theta)$ Training vs. emulator') plt.xlabel(r'$\theta$') plt.ylabel(r'$w(\theta)$') plt.show()

In [ ]:
from pearce.mocks import compute_prim_haloprop_bins, cat_dict

In [ ]:
cosmo_params = {'simname':'chinchilla', 'Lbox':400.0, 'scale_factors':[a]}
cat = cat_dict[cosmo_params['simname']](**cosmo_params)#construct the specified catalog!

cat.load_catalog(a)
#halo_masses = cat.halocat.halo_table['halo_mvir']

In [ ]:
cat.load_model(a, 'hsabRedMagic')

In [ ]:
binno = 1
params = {pname:val for pname, val in zip(emu._ordered_params.iterkeys(), emu.x[binno*binlen,:-1])}
cat.populate(params)

wt = cat.calc_wt(theta_bins, do_jackknife=False,n_cores=1)

plt.plot(emu.scale_bin_centers,1+wt) plt.plot(emu.scale_bin_centers, 1+10**emu.y[binno*emu.scale_bin_centers.shape[0]:(binno+1)*emu.scale_bin_centers.shape[0]]) #plt.yscale('log') plt.loglog() plt.xlim([2.25/60, 275/60]) plt.ylim([0.8, 4.0])

In [ ]:
theta_bins = np.logspace(np.log10(2.5), np.log10(250), 20)/60
tpoints = (theta_bins[1:]+theta_bins[:-1])/2

In [ ]:
fig = plt.figure(figsize=(45,14))


emulation_point = [('f_c', 0.233), ('logM0', 12.0), ('sigma_logM', 0.333),
                    ('alpha', 1.053),('logM1', 13.5), ('logMmin', 12.033)]

em_params = dict(emulation_point)

em_params.update(fixed_params)
del em_params['z']

fixed_params2 = {'mean_occupation_satellites_assembias_param1':0.0,
                'mean_occupation_centrals_assembias_param1':0.0,
                'disp_func_slope_satellites':1.0,
                'disp_func_slope_centrals':1.0}

for idx, (param, bounds) in enumerate(emu._ordered_params.iteritems()):
    if param == 'r':
        continue
    wt_vals = []
    new_em_params = {}
    new_em_params.update(em_params)
    new_em_params.update(fixed_params2)
    for v in np.linspace(bounds[0], bounds[1], 6):
        new_em_params[param] = v
        wt_vals.append(emu.emulate_wrt_r(new_em_params, tpoints))
    wt_vals = np.array(wt_vals)
    
    pal = sns.cubehelix_palette(wt_vals.shape[0], start=idx, rot=0.3,\
                            dark=0.0, light=.60,reverse = True)
    #sns.palplot(pal)

    sns.set_palette(pal)

    #sns.set_style("darkgrid", {"axes.facecolor": "0.85"})
    plt.subplot(5,2,idx+1)

    for color, wt, v in zip(pal, wt_vals,np.linspace(bounds[0], bounds[1], 6) ):
        plt.plot(tpoints, 1+wt[0,:], color = color, label = r'%s = %.1f'%(param,v) )
    #plt.loglog()
    plt.xscale('log')
    plt.legend(loc='best')
    plt.xlim([0.1, 4])
    plt.title(r'$w(\theta)$ variance by %s'%param)
    plt.xlabel(r'$\theta$')
    plt.ylabel(r'$w(\theta)$')
plt.show()

In [ ]: